using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Globalization;
using Jaws.Core.Web.Data;
using System.Xml.Serialization;

namespace Jaws.Core.Web.Entities.Roles
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable()]
    [XmlRoot("roles")]
    [XmlDataDirectory("roles")]
    public class RoleCollection : XmlCollectionBase<RoleCollection, Role>
    {
        private object _lockObject = new object();
        private static RoleCollection roles = new RoleCollection();
        
        /// <summary>
        /// Initializes a new instance of the <see cref="RoleCollection"/> class.
        /// </summary>
        public RoleCollection() : base() { }

        internal RoleCollection(IList<Role> roles) : base(roles) { }

        /// <summary>
        /// Finds the name of the by.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public Role FindByName(string name)
        {
            foreach (Role r in this)
            {
                if (string.Compare(r.Name, name, true, CultureInfo.CurrentCulture) == 0) { return r; }
            }

            return null;
        }

    }
}